import { fakeChartData, queryActivities, queryCurrent, queryProjectNotice } from './service';

const Model = {
  namespace: 'workSpace',
  state: {
    currentUser: undefined,
    projectNotice: [],
    activities: [],
    radarData: [],
  },
  effects: {
    *init(_, { put }) {
      // yield put({
      //   type: 'fetchUserCurrent',
      // });
      yield put({
        type: 'fetchProjectNotice',
      });
      yield put({
        type: 'fetchActivitiesList',
      });
      yield put({
        type: 'fetchChart',
      });
    },

    *fetchUserCurrent(_, { call, put }) {
      const response = call(queryCurrent);
      debugger
      let r = {
        notifyCount: 12,
        unreadCount: 11,
        country: 'China'
      };
      let res = Object.assign(response, r);
      yield put({
        type: 'save',
        payload: {
          currentUser: res,
        },
      });
    },

    *fetchProjectNotice(_, { call, put }) {
      const response = JSON.parse("[{\"id\":\"xxx1\",\"title\":\"Alipay\",\"logo\":\"https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png\",\"description\":\"那是一种内在的东西，他们到达不了，也无法触及的\",\"updatedAt\":\"2022-03-24T01:14:15.811Z\",\"member\":\"科学搬砖组\",\"href\":\"\",\"memberLink\":\"\"},{\"id\":\"xxx2\",\"title\":\"Angular\",\"logo\":\"https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png\",\"description\":\"希望是一个好东西，也许是最好的，好东西是不会消亡的\",\"updatedAt\":\"2017-07-24T00:00:00.000Z\",\"member\":\"全组都是吴彦祖\",\"href\":\"\",\"memberLink\":\"\"},{\"id\":\"xxx3\",\"title\":\"Ant Design\",\"logo\":\"https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png\",\"description\":\"城镇中有那么多的酒馆，她却偏偏走进了我的酒馆\",\"updatedAt\":\"2022-03-24T01:14:15.811Z\",\"member\":\"中二少女团\",\"href\":\"\",\"memberLink\":\"\"},{\"id\":\"xxx4\",\"title\":\"Ant Design Pro\",\"logo\":\"https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png\",\"description\":\"那时候我只会想自己想要什么，从不想自己拥有什么\",\"updatedAt\":\"2017-07-23T00:00:00.000Z\",\"member\":\"程序员日常\",\"href\":\"\",\"memberLink\":\"\"},{\"id\":\"xxx5\",\"title\":\"Bootstrap\",\"logo\":\"https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png\",\"description\":\"凛冬将至\",\"updatedAt\":\"2017-07-23T00:00:00.000Z\",\"member\":\"高逼格设计天团\",\"href\":\"\",\"memberLink\":\"\"},{\"id\":\"xxx6\",\"title\":\"React\",\"logo\":\"https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png\",\"description\":\"生命就像一盒巧克力，结果往往出人意料\",\"updatedAt\":\"2017-07-23T00:00:00.000Z\",\"member\":\"骗你来学计算机\",\"href\":\"\",\"memberLink\":\"\"}]")
      yield put({
        type: 'save',
        payload: {
          projectNotice: Array.isArray(response) ? response : [],
        },
      });
    },

    *fetchActivitiesList(_, { call, put }) {
      const response = JSON.parse("[{\"id\":\"trend-1\",\"updatedAt\":\"2022-03-24T01:14:15.811Z\",\"user\":{\"name\":\"曲丽丽\",\"avatar\":\"https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png\"},\"group\":{\"name\":\"高逼格设计天团\",\"link\":\"http://github.com/\"},\"project\":{\"name\":\"六月迭代\",\"link\":\"http://github.com/\"},\"template\":\"在 @{group} 新建项目 @{project}\"},{\"id\":\"trend-2\",\"updatedAt\":\"2022-03-24T01:14:15.811Z\",\"user\":{\"name\":\"付小小\",\"avatar\":\"https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png\"},\"group\":{\"name\":\"高逼格设计天团\",\"link\":\"http://github.com/\"},\"project\":{\"name\":\"六月迭代\",\"link\":\"http://github.com/\"},\"template\":\"在 @{group} 新建项目 @{project}\"},{\"id\":\"trend-3\",\"updatedAt\":\"2022-03-24T01:14:15.811Z\",\"user\":{\"name\":\"林东东\",\"avatar\":\"https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png\"},\"group\":{\"name\":\"中二少女团\",\"link\":\"http://github.com/\"},\"project\":{\"name\":\"六月迭代\",\"link\":\"http://github.com/\"},\"template\":\"在 @{group} 新建项目 @{project}\"},{\"id\":\"trend-4\",\"updatedAt\":\"2022-03-24T01:14:15.811Z\",\"user\":{\"name\":\"周星星\",\"avatar\":\"https://gw.alipayobjects.com/zos/rmsportal/WhxKECPNujWoWEFNdnJE.png\"},\"project\":{\"name\":\"5 月日常迭代\",\"link\":\"http://github.com/\"},\"template\":\"将 @{project} 更新至已发布状态\"},{\"id\":\"trend-5\",\"updatedAt\":\"2022-03-24T01:14:15.811Z\",\"user\":{\"name\":\"朱偏右\",\"avatar\":\"https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png\"},\"project\":{\"name\":\"工程效能\",\"link\":\"http://github.com/\"},\"comment\":{\"name\":\"留言\",\"link\":\"http://github.com/\"},\"template\":\"在 @{project} 发布了 @{comment}\"},{\"id\":\"trend-6\",\"updatedAt\":\"2022-03-24T01:14:15.811Z\",\"user\":{\"name\":\"乐哥\",\"avatar\":\"https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png\"},\"group\":{\"name\":\"程序员日常\",\"link\":\"http://github.com/\"},\"project\":{\"name\":\"品牌迭代\",\"link\":\"http://github.com/\"},\"template\":\"在 @{group} 新建项目 @{project}\"}]")
      yield put({
        type: 'save',
        payload: {
          activities: Array.isArray(response) ? response : [],
        },
      });
    },

    *fetchChart(_, { call, put }) {
      const radarData  = JSON.parse("[{\"name\":\"个人\",\"label\":\"引用\",\"value\":10},{\"name\":\"个人\",\"label\":\"口碑\",\"value\":8},{\"name\":\"个人\",\"label\":\"产量\",\"value\":4},{\"name\":\"个人\",\"label\":\"贡献\",\"value\":5},{\"name\":\"个人\",\"label\":\"热度\",\"value\":7},{\"name\":\"团队\",\"label\":\"引用\",\"value\":3},{\"name\":\"团队\",\"label\":\"口碑\",\"value\":9},{\"name\":\"团队\",\"label\":\"产量\",\"value\":6},{\"name\":\"团队\",\"label\":\"贡献\",\"value\":3},{\"name\":\"团队\",\"label\":\"热度\",\"value\":1},{\"name\":\"部门\",\"label\":\"引用\",\"value\":4},{\"name\":\"部门\",\"label\":\"口碑\",\"value\":1},{\"name\":\"部门\",\"label\":\"产量\",\"value\":6},{\"name\":\"部门\",\"label\":\"贡献\",\"value\":5},{\"name\":\"部门\",\"label\":\"热度\",\"value\":7}]")
      yield put({
        type: 'save',
        payload: {
          radarData,
        },
      });
    },
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },

    clear() {
      return {
        currentUser: undefined,
        projectNotice: [],
        activities: [],
        radarData: [],
      };
    },
  },
};
export default Model;
